/**
 * Created by mac on 18/1/17.
 */
layui.define(['jquery' , 'laytpl'],function(exports){
    var $ = layui.jquery,
        laytpl = layui.laytpl;
    var infoContent = '<div role="alert" class="el-message el-message--{{d.type}} el-message-to">' +
                        '<i class="el-message__icon el-icon-{{d.type}} zl zlIcon-{{d.type}}"></i>' +
                        '<p class="el-message__content">{{d.content}}</p>' +
                    '</div>';
    var obj = {
        hello: function(str){
            alert('Hello '+ (str||'mymod'));
        },
        msg:function (obj) {
            if(typeof obj.type === 'undefined'){
                obj.type = 'info';
            }
            if(typeof obj.duration === 'undefined'){
                obj.duration = 3000;
            }
            laytpl(infoContent).render(obj, function(html){
                $('body').append(html);
                var _target = $('.el-message');
                setTimeout(function () {
                    _target.removeClass('el-message-to');
                },100);
                setTimeout(function () {
                    _target.addClass('el-message-to');
                },obj.duration);
                setTimeout(function () {
                    _target.remove();
                },parseInt(obj.duration) + 500);
            });
        }
    };

    exports('message', obj);
});